/**
 * Created by hxsd on 2016/7/20.
 */

$(function(){
    var count=0;
    $(".banner li").css("height","0");
    $(".shufflingRing a").eq(4).find("img").addClass("haha");
    $(".food_pic").css({opacity:0,marginLeft:"0"});
    $(window).scroll(function(){
        if($(window).scrollTop()>1000){
            $(".food_pic").animate({
                opacity:1,
                filter:"Alpha(opacity=100)",
                marginLeft:"154px"
            },1000,function(){
                $(".food_text h2").animate({
                    height:"413px"
                },800,function(){
                    liDelayTwo(0,0);
                    liDelayTwo(1,800);
                    liDelayTwo(2,1600);
                    liDelayTwo(3,2400);
                    liDelayTwo(4,3200);
                    setTimeout(function(){
                        $(".explain").animate({
                            opacity:"1",
                            filter:"Alpha(opacity=100)"
                        },1000)
                    },4000)
                })
            })
        }
    });
    $(".banner").css("width","0").animate({
        width:"100%"
    },2000,function(){
        $(".banner .inner").animate({
            opacity:1,
            filter:"Alpha(opacity=100)"
        },1000,function(){
            liDelay(3,0);
            liDelay(4,400);
            liDelay(5,800);
            liDelay(2,1200);
            liDelay(1,1600);
            liDelay(0,2000);
        })
    });
    $(".shuffling .left").on("click",function(){
        count--;
        removeHaha();
        $(".shufflingRing a").eq(count+4).find("img").addClass("haha");
        if(count>=0){
            $(".shufflingRing .box").animate({
                left:"+=309px"
            });
        }else {
            $(".shufflingRing .box").animate({
                left:"+=309px"
            },function(){
                $(".shufflingRing .box").css("left","-1545px")
            });
            count=2;
            $(".shufflingRing a").eq(count+4).find("img").addClass("haha");
        }
    });
    $(".shuffling .right").on("click",function(){
        count++;
        removeHaha();
        $(".shufflingRing a").eq(count+4).find("img").addClass("haha");

        if(count<3){
            $(".shufflingRing .box").animate({
                left:"-=309px"
            });
        }else {
            $(".shufflingRing .box").animate({
                left:"-=309px"
            },function(){
                $(".shufflingRing .box").css("left","-927px")
            });
            count=0;
            $(".shufflingRing a").eq(count+4).find("img").addClass("haha");
        }

    });
});
function liDelay(index,time){
    setTimeout(function(){
        $(".banner li").eq(index).animate({
            height:"135px"
        });
    },time);
}
function liDelayTwo(index,time){
    setTimeout(function(){
        $(".poem li").eq(index).animate({
            height:"96px"
        },800);
    },time);
}
function removeHaha(){
    for(var i=3;i<8;i++){
        $(".shufflingRing a").eq(i).find("img").removeClass("haha");
    }
}